package com.laogao.utils;

/**
 * @author laogao
 */
public class FileUtils {


    /**
     * 图片格式判断
     *
     * @param suffix
     * @return
     */
    public static boolean imageType(String suffix) {
        return suffix.equalsIgnoreCase("JPG") || suffix.equalsIgnoreCase("JPEG") || suffix.equalsIgnoreCase("GIF")
                || suffix.equalsIgnoreCase("PNG") || suffix.equalsIgnoreCase("BMP") || suffix.equalsIgnoreCase("PCX")
                || suffix.equalsIgnoreCase("TGA") || suffix.equalsIgnoreCase("PSD") || suffix.equalsIgnoreCase("TIFF");
    }

    /**
     * 2017-11-16 09:48:22 张
     * <p>
     * 音频格式判断
     *
     * @param suffix
     * @return
     */
    public static boolean audioType(String suffix) {
        return suffix.equalsIgnoreCase("mp3") || suffix.equalsIgnoreCase("OGG") || suffix.equalsIgnoreCase("WAV")
                || suffix.equalsIgnoreCase("REAL") || suffix.equalsIgnoreCase("APE") || suffix.equalsIgnoreCase("MODULE")
                || suffix.equalsIgnoreCase("MIDI") || suffix.equalsIgnoreCase("VQF") || suffix.equalsIgnoreCase("CD");
    }

    /**
     * 视频格式判断
     *
     * @return
     */
    public static boolean videoType(String suffix) {
        return suffix.equalsIgnoreCase("mp4") || suffix.equalsIgnoreCase("avi") || suffix.equalsIgnoreCase("MPEG-1")
                || suffix.equalsIgnoreCase("RM") || suffix.equalsIgnoreCase("ASF") || suffix.equalsIgnoreCase("WMV")
                || suffix.equalsIgnoreCase("qlv") || suffix.equalsIgnoreCase("MPEG-2") || suffix.equalsIgnoreCase("MPEG4")
                || suffix.equalsIgnoreCase("mov") || suffix.equalsIgnoreCase("3gp");
    }

    /**
     * 文档类型 xlsx、.xls
     *
     * @return
     */
    public static boolean officeType(String suffix) {
        return suffix.equalsIgnoreCase("pdf") || suffix.equalsIgnoreCase("txt")
                || suffix.equalsIgnoreCase("docx") || suffix.equalsIgnoreCase("doc")
                || suffix.equalsIgnoreCase("pptx") || suffix.equalsIgnoreCase("ppt")
                || suffix.equalsIgnoreCase("xlsx") || suffix.equalsIgnoreCase("xlsx");
    }

    /**
     * 判断文档类型 1:图片2:音频 3:视频 4:文档 5未知类型
     *
     * @param extension
     * @return
     */
    public static int checkType(String extension) {

        if (FileUtils.imageType(extension)) {
            return 1;
        }
        if (FileUtils.audioType(extension)) {
            return 2;
        }
        if (FileUtils.videoType(extension)) {
            return 3;
        }
        if (FileUtils.officeType(extension)) {
            return 4;
        }
        return 5;
    }

}

